import 'package:flutter/material.dart';

class PaddingPage extends StatelessWidget {
  const PaddingPage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text("Padding Widget 示例")),
      body: SingleChildScrollView(
        padding: const EdgeInsets.all(16),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            _buildTitle("1. EdgeInsets.all - 四边统一间距"),
            Container(
              color: Colors.blueAccent,
              child: Padding(
                padding: const EdgeInsets.all(20),
                child: Container(
                  color: Colors.orange,
                  height: 50,
                  child: const Center(child: Text("EdgeInsets.all(20)")),
                ),
              ),
            ),
            const SizedBox(height: 20),

            _buildTitle("2. EdgeInsets.only - 单独控制某一边的间距"),
            Container(
              color: Colors.green,
              child: Padding(
                padding: const EdgeInsets.only(left: 30, top: 10),
                child: Container(
                  color: Colors.orange,
                  height: 50,
                  child: const Center(child: Text("EdgeInsets.only(left:30, top:10)")),
                ),
              ),
            ),
            const SizedBox(height: 20),

            _buildTitle("3. EdgeInsets.symmetric - 水平/垂直方向统一间距"),
            Container(
              color: Colors.purple,
              child: Padding(
                padding: const EdgeInsets.symmetric(horizontal: 40, vertical: 10),
                child: Container(
                  color: Colors.orange,
                  height: 50,
                  child: const Center(
                    child: Text("EdgeInsets.symmetric(horizontal:40, vertical:10)"),
                  ),
                ),
              ),
            ),
            const SizedBox(height: 20),

            _buildTitle("4. EdgeInsets.fromLTRB - 分别指定四边间距"),
            Container(
              color: Colors.red,
              child: Padding(
                padding: const EdgeInsets.fromLTRB(20, 30, 40, 10),
                child: Container(
                  color: Colors.orange,
                  height: 50,
                  child: const Center(
                    child: Text("EdgeInsets.fromLTRB(20,30,40,10)"),
                  ),
                ),
              ),
            ),
            const SizedBox(height: 20),

            _buildTitle("5. 嵌套 Padding"),
            Container(
              color: Colors.blueGrey,
              child: Padding(
                padding: const EdgeInsets.all(10),
                child: Padding(
                  padding: const EdgeInsets.all(20),
                  child: Container(
                    color: Colors.orange,
                    height: 50,
                    child: const Center(
                      child: Text("内外双重 Padding"),
                    ),
                  ),
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }

  Widget _buildTitle(String text) {
    return Padding(
      padding: const EdgeInsets.symmetric(vertical: 8),
      child: Text(
        text,
        style: const TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
      ),
    );
  }
}
